[XEND] Prevent uuid double use.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 10 Jul 2006 14:10:00 +0000 (15:10 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Mon, 10 Jul 2006 14:10:00 +0000 (15:10 +0100)
A check_uuid() in this patch checks on uuid of the
VM configuration definition. If specified uuid is
already used with the others VM, the xm create command
does not create the VM. The xm create command error occurs.

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py

index 54ef911a917d788133a79335b84bea1dfef51c09..8c6a4e182f4c7bb1d792bba5d8d520dc8ef63522 100644 (file)
@@ -347,6 +347,19 @@ class XendDomain:
             self.domains_lock.release()
 
 
+    def domain_lookup_by_uuid_nr(self, uuid):
+        self.domains_lock.acquire()
+        try:
+            matching = filter(lambda d: d.getUuid() == uuid,
+                              self.domains.values())
+            n = len(matching)
+            if n == 1:
+                return matching[0]
+            return None
+        finally:
+            self.domains_lock.release()
+
+
     def privilegedDomain(self):
         self.domains_lock.acquire()
         try:
index 665eb927d3f3f3c05f039585f66341d4df7e6b15..b100a7d5579759df6b5f3cb0b5c4c4bb4a06a588 100644 (file)
@@ -396,6 +396,10 @@ def domain_by_name(name):
     return XendDomain.instance().domain_lookup_by_name_nr(name)
 
 
+def domain_by_uuid(uuid):
+    return XendDomain.instance().domain_lookup_by_uuid_nr(uuid)
+
+
 def shutdown_reason(code):
     """Get a shutdown reason from a code.
 
@@ -581,6 +585,7 @@ class XendDomainInfo:
             defaultInfo('security',     lambda: None)
 
             self.check_name(self.info['name'])
+            self.check_uuid(self.info['uuid'])
 
             if isinstance(self.info['image'], str):
                 self.info['image'] = sxp.from_string(self.info['image'])
@@ -778,6 +783,9 @@ class XendDomainInfo:
     def getName(self):
         return self.info['name']
 
+    def getUuid(self):
+        return self.info['uuid']
+
     def getDomainPath(self):
         return self.dompath
 
@@ -1207,6 +1215,23 @@ class XendDomainInfo:
                           (name, self.domid, dominfo.domid))
 
 
+    def check_uuid(self, uuid):
+        """The same uuid cannot be used for more than one vm at the same time.
+
+        @param uuid: uuid
+        @raise: VmError if same uuid is used
+        """
+        dominfo = domain_by_uuid(uuid)
+        if not dominfo:
+            return
+        if self.domid is None:
+            raise VmError("uuid '%s' already in use by domain %d" %
+                          (uuid, dominfo.domid))
+        if dominfo.domid != self.domid:
+            raise VmError("uuid '%s' is used in both domains %d and %d" %
+                          (uuid, self.domid, dominfo.domid))
+
+
     def construct(self):
         """Construct the domain.